package fightdizhu;

import java.util.*;

public class DouDizhu {
    public static void main(String[] args) {
        /**
         * 1.组装牌
         * 集合：map list
         */
        HashMap<Integer, String> poker = new HashMap<>();
        ArrayList<Integer> pokerIndex = new ArrayList<>();

        List<String> numbers = Arrays.asList("2", "3", "4", "5", "6", "7", "8", "9", "10", "A", "k", "Q", "J");
        List<String> colors = Arrays.asList("红桃", "黑桃", "梅花", "方块");

        int index = 0;
        poker.put(index, "大王");
        pokerIndex.add(index);
        index++;

        poker.put(index, "小王");
        pokerIndex.add(index);
        index++;

        for (String number : numbers) {
            for (String color : colors) {
                poker.put(index, color + number);
                pokerIndex.add(index);
                index++;
            }
        }
        //2.洗牌
        Collections.shuffle(pokerIndex);
//        System.out.println("pokerIndex = " + pokerIndex);

//        System.out.println("poker = " + poker);

           System.out.println("pokerIndex = " + pokerIndex);

        //3.发牌
        ArrayList<Integer> play01 = new ArrayList<>();
        ArrayList<Integer> play02 = new ArrayList<>();
        ArrayList<Integer> play03 = new ArrayList<>();
        ArrayList<Integer> diPai = new ArrayList<>();

        for (int i = 0; i < pokerIndex.size(); i++) {
            Integer in = pokerIndex.get(i);
            if (i >= 51) {
                diPai.add(in);
            } else if (i % 3 == 0) {
                play01.add(in);
            } else if (i % 3 == 1) {
                play02.add(in);
            } else if (i % 3 == 2) {
                play03.add(in);
            }
        }

        //4.整理牌
        Collections.sort(play01);
        Collections.sort(play02);
        Collections.sort(play03);
        //5.看牌
        show("小张", poker, play01);
        show("小杨", poker, play02);
        show("小李", poker, play03);
        show("底牌", poker, diPai);
    }

    public static void show(String name, HashMap<Integer, String> poker, ArrayList<Integer> list) {
        System.out.println(name + ":");
        for (Integer key : list) {
            String s = poker.get(key);
            System.out.print(s + " ");
        }
        System.out.println();
    }
}
